package com.ecommerce.product.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 商品规格实体类
 * 
 * @author ecommerce-team
 * @version 1.0.0
 */
@Entity
@Table(name = "product_spec")
@TableName("product_spec")
public class ProductSpec {
    
    /**
     * 规格ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    
    /**
     * 商品ID
     */
    @NotNull(message = "商品ID不能为空")
    @Column(name = "product_id", nullable = false)
    private Long productId;
    
    /**
     * 规格名称（如：颜色、尺寸、内存等）
     */
    @NotBlank(message = "规格名称不能为空")
    @Column(name = "name", nullable = false, length = 50)
    private String name;
    
    /**
     * 规格值列表（JSON格式存储，如：["红色", "蓝色", "黑色"]）
     */
    @Column(name = "values", columnDefinition = "text")
    private String values;
    
    /**
     * 排序权重
     */
    @Column(name = "sort_order", columnDefinition = "int default 0")
    private Integer sortOrder;
    
    /**
     * 创建时间
     */
    @TableField(fill = FieldFill.INSERT)
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;
    
    /**
     * 更新时间
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;
    
    /**
     * 逻辑删除：0-未删除，1-已删除
     */
    @TableLogic
    @Column(name = "deleted", columnDefinition = "tinyint default 0")
    private Integer deleted;
    
    // 以下字段不存储到数据库，仅用于返回给前端
    
    /**
     * 规格值列表（不存储到数据库）
     */
    @Transient
    @TableField(exist = false)
    private List<String> valueList;
    
    // Getter and Setter methods
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }
    
    public Long getProductId() { return productId; }
    public void setProductId(Long productId) { this.productId = productId; }
    
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    
    public String getValues() { return values; }
    public void setValues(String values) { this.values = values; }
    
    public Integer getSortOrder() { return sortOrder; }
    public void setSortOrder(Integer sortOrder) { this.sortOrder = sortOrder; }
    
    public LocalDateTime getCreateTime() { return createTime; }
    public void setCreateTime(LocalDateTime createTime) { this.createTime = createTime; }
    
    public LocalDateTime getUpdateTime() { return updateTime; }
    public void setUpdateTime(LocalDateTime updateTime) { this.updateTime = updateTime; }
    
    public Integer getDeleted() { return deleted; }
    public void setDeleted(Integer deleted) { this.deleted = deleted; }
    
    public List<String> getValueList() { return valueList; }
    public void setValueList(List<String> valueList) { this.valueList = valueList; }
}